﻿#ifndef _CSERVER_LISTENER_MODULE_H_
#define _CSERVER_LISTENER_MODULE_H_

#include "CModule.h"
#include "CMsg.h"

#include <winsock2.h>

#pragma comment(lib,"WSOCK32.LIB")
#pragma comment(lib,"ws2_32.lib") 

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _cserverlistener_module_ {
	CModule parent; // base

	//attribute
	//CMsgDispatcher msg_dispatcher;
	CModule* msg_executer;
	SOCKET socket_for_listen;
	unsigned short listen_on_port;
	
	SOCKET socketList[WSA_MAXIMUM_WAIT_EVENTS];
	HANDLE EventList[WSA_MAXIMUM_WAIT_EVENTS];
	SOCKADDR_IN	Addr[WSA_MAXIMUM_WAIT_EVENTS];
	int mCount;

	//action
	int(*run)(struct _cserverlistener_module_*);
	int(*send_msg_to_client)(SOCKET* client, CMsg* msg);
} CServerListenerModule;

int construct_server_listener(CServerListenerModule* thes, const char* module_name, unsigned short listen_on_port, CModule* msg_executer);

#ifdef __cplusplus
}
#endif
#endif
